/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CommonData;

import DataModel.Country;
import CommonData.DataLayer.CommonDataDataManager;
import java.util.*;

/**
 *
 * @author Rainiero
 */
public class CommonDataManager {

    // <editor-fold defaultstate="collapsed" desc="Attributes">
    private HashMap <Integer, Country> _countries;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Singleton">
    private static CommonDataManager _instance = new CommonDataManager();

    private CommonDataManager()
    {
        Country[] countries = CommonDataDataManager.GetInstance().GetCountries();
        _countries = new HashMap<Integer, Country>();
        for(int countryIndex = 0; countryIndex < countries.length; countryIndex++)
            _countries.put(countries[countryIndex].getId(), countries[countryIndex]);
    }

    public static CommonDataManager GetInstance()
    {
        return _instance;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Public Methods">
    public Country[] GetCountries()
    {
        Country[] countryArray = new Country[_countries.size()];
        return _countries.values().toArray(countryArray);
    }

    public Country GetCountry(int countryId)
    {
        try
        {
            return _countries.get(countryId);
        }
        catch(Exception ex){ }
        return null;
    }
    // </editor-fold>

}
